<?php

namespace Controller;

abstract class Base extends \Lib\Core\Controller {

    /**
     * 当前登录的用户信息.
     *
     * @var array
     */
    public $currentUserInfo;
    public $uri;

    public function actionBefore() {
        $this->assign('_metaTitle', '');
        $this->assign('_metaKeywords', '');
        $this->assign('_metaDescription', '');
        $mask = $this->getUserMask();
        $this->currentUserInfo = \Business\User::instance()->getCurrentUserInfo($mask);
        $this->uri = $_SERVER['REQUEST_URI'];
        $fromUrl = $this->getParam('fromurl');
        $fromUrl = urldecode($fromUrl);
        $fromUrl = $fromUrl ? $fromUrl : '/';
        $this->assign('_fromUrl', $fromUrl);
        $this->assign('_currentUserInfo', $this->currentUserInfo);
        $this->assign('_uri', $this->uri);
        $this->assign('_mask', $this->getUserMask());
        $this->setStaticFileVersion('1.2');
    }

    public function setMeta($title, $keywords = '', $description = '') {
        $webName = '天府标局';
        if ($title) {
            $title = $webName . ' - ' . $title;
        } else {
            $title = $webName;
        }
        $this->assign('_metaTitle', $title);
        if ($keywords) {
            $this->assign('_metaKeywords', $keywords);
        }
        if ($description) {
            $this->assign('_metaDescription', $description);
        }
    }

    public function mustLogin($checkPhoneVerification = true) {
        if (!$this->currentUserInfo) {
            \Util\Comm::redirect('/login.html?fromurl=' . urlencode($this->uri));
        }
        if ($this->currentUserInfo['PhoneVerification'] == 0 && $checkPhoneVerification) {
            \Util\Comm::redirect('/Passport/BindPhone?fromurl=' . urlencode($this->uri));
        }
    }

}
